<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
	<title>门票管理</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />

  <!-- 新模板 -->
<link rel="shortcut icon" href="<c:url value='/template/new_muban/images/favicon.ico'/>" type="image/x-icon"/>

<!-- 最新导入 -->
<script type="text/javascript" src="<c:url value='/template/new_muban/js/jquery-min-1.7.js'/>"></script> 
<link rel="stylesheet" href="<c:url value='/template/new_muban/css/font.css'/>">
<link rel="stylesheet" href="<c:url value='/template/new_muban/css/xadmin.css'/>">   
<script src="<c:url value='/template/new_muban/lib/layui/layui.js'/>" charset="utf-8"></script> 
<script type="text/javascript" src="<c:url value='/template/new_muban/js/xadmin.js'/>"></script>

<link rel="stylesheet" href="<c:url value='/template/new_muban/css/login.css'/>"><%-- 
<script type="text/javascript" src="<c:url value='/template/lead_into/num/js/jquery.min.js'/>"></script> --%>
<script type="text/javascript" src="<c:url value='/template/lead_into/num/js/num-alignment.js'/>"></script>
<!--     <script src="http://code.jquery.com/jquery-1.11.0-beta1.js"></script> -->
<style type="text/css">
	/*圆形头像  */
	/* #divcss5{ margin:10px auto}  */
	#divcss5 img{ border-radius:50%} 
	.x-so input.layui-input {
    	width: 150px;
	}
	/*发灰*/
	.gray { 
	    -webkit-filter: grayscale(100%);
	    -moz-filter: grayscale(100%);
	    -ms-filter: grayscale(100%);
	    -o-filter: grayscale(100%);
	    
	    filter: grayscale(100%);
		
	    filter: gray;
	}
	
input[type=checkbox] {
  -ms-transform: scale(2); /* IE */
  -moz-transform: scale(2); /* FireFox */
  -webkit-transform: scale(2); /* Safari and Chrome */
  -o-transform: scale(2); /* Opera */
}
</style>


	 <script type="text/javascript">

        $(function () {
             $("input[type=checkbox][name=ckb_select]").click(function () {
                var objs = $("input[type=checkbox][name=ckb_select]:checked").map(function () {
                    var tr = $(this).closest("tr");
		              var idd = "ticket_"+$(tr).find("td:eq(1)").text();
                    //return { "dj": $(tr).find("td:eq(1)").text(), "zhj": $(tr).find("td:eq(2)").text(), "zp": $(tr).find("td:eq(3)").text() };
                    
                    return { "dj": $(tr).find("td:eq(1)").text(), "zhj": $(tr).find("td:eq(5)").text(), "zp": $("#"+idd).val()};
                }).get();

                var tj = 0, zhj = 0, zp = 0;
                $.each(objs, function (i, d) {
                	console.log(d.dj);
                	//id
                    tj = parseInt(tj) + parseInt(d.dj);
                	//数量
                    zhj = parseInt(zhj) + parseInt(d.zhj);
                	//价格
                    zp = parseInt(zp) + parseInt(d.zp);
                }) 
                console.log("id  tj : "+tj);
                console.log("zhj : "+zhj);
                console.log("zp : "+zp);
               $("#tb_tj tr:last td:eq(1)").text(tj + "元");
                $("#tb_tj tr:last td:eq(2)").text(zhj + "元");
                $("#tb_tj tr:last td:eq(3)").text(zp + "件"); 
            }) 
            
        	  /* $("input[type=checkbox][name=ckb_select]").click(function () {
 		    	 $('tbody input').each(function(index, el) {
 			           if($(this).prop('checked')){
 			              //ids.push($(this).val())
 			              //获取数量input
 			        	  var tr = $(this).closest("tr");
 			             
 			              var idd = "ticket_"+$(tr).find("td:eq(1)").text();
 		                  console.log($("#"+idd).val());
 			             
 		                  console.log("id : "+ $(tr).find("td:eq(1)").text()+" 单价  :  "+ $(tr).find("td:eq(5)").text() + " 数量  : "+$("#"+idd).val());
 		                 
 			           }
 			       });
 				

 		     })   
             */
            
        })
   
    </script>

</head>
<body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">牡丹园</a>
        <a href="">门票售卖</a>
        <a>
          <cite>门票列表</cite></a>
      </span>
     <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
    </div>
	  <div class="layui-fluid">
	            <div class="layui-row layui-col-space15">
	                <div class="layui-col-md12">
	                    <div class="layui-card">
            <div class="layui-card-body "><!-- onsubmit="return verifyDate();" -->
                             
                        </div> 
     <%--   <div class="layui-card-header">
        <button class="layui-btn" onclick="xadmin.open('新增门票','<c:url value='/findAllSmallTicket.do'/>')"><i class="layui-icon"></i>新增门票</button>
      </div>  --%>
      <div class="layui-card-body layui-table-body layui-table-main">
       <table class="layui-table" id="dataTable" lay-filter="test">
        <thead>
          <tr>
            <th></th>
            <th style="display:none">ID</th>
            <th>缩略图</th>
            <th>门票信息</th>
            <th>门票说明</th>
            <th>单价</th>
            <th>数量</th></tr>
        </thead>
        <tbody  id="x-img">
    
          <c:forEach items="${allTicket}" var="ticket" varStatus="sm">
            <tr>
             <td><center><input type="checkbox" name="ckb_select" id="ckb_select"/></center></td>
             <td style="display:none">${ticket.id}</td>
             <td><img alt="${ticket.goodsInfo}" src="${ticket.imgUrl}" width="150px"></td>
            <td>
				<div title='${ticket.goodsInfo}'> 
            	<font size="1">
		             ${fn:substring(ticket.goodsInfo, 0,20)}
		             <c:if test="${fn:length(ticket.goodsInfo)>20}"> ... </c:if>
		             </font>
		          </div>
			</td>
            <td>${ticket.goodsParams}</td>
            <td>${ticket.price}</td>
            <td><%-- ${ticket.goodsCount} --%>
            	<input id="ticket_${ticket.id}" data-step="1" data-min="1"  data-digit="0" value="1"  data-edit="true"/>
            </td>
        
          </tr>
          
          </c:forEach>
		<tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>
        </tbody>
      </table>
      <blockquote class="layui-elem-quote" style="margin-top: 10px;">
 		<div style="margin-right: 10px;">
 		<button class="layui-btn" onclick="qx();">结算</button>
 		</div>
	  </blockquote>
    
      </div>
 </div>
  </div>
   </div>
    </div>

    <script>
    //时间
      layui.use('laydate', function(){
        var laydate = layui.laydate;
        
        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
      });


    </script>

     
     <!-- 1 绿√  2 红X  3 黄?  4  灰锁  5  红哭脸  6 绿笑脸 7 黄!  --> 
    <!-- //页面跳转 -->
<script type="text/javascript">
	function checkNum(sumNumber,start,end,u_nickname,u_name,u_phone,t_name,order_status,page_num){
		var num = $(".inputNum").val();
		/* //prompt层		//prompt层
		layer.prompt({title: '输入任何口令，并确认', formType: 1}, function(pass, index){
			  layer.close(index);
			  layer.prompt({title: '随便写点啥，并确认', formType: 2}, function(text, index){
			    layer.close(index);
			    layer.msg('演示完毕！您的口令：'+ pass +'<br>您最后写下了：'+text);
			  });
			});
		return false; */
		
		//alert(sumNumber+"/"+num+"/"+s_name+"/"+s_contact+"/"+s_phone+"/"+openid+"/"+pay_status+"/"+start+"/"+end+"/"+page_num );
		if(!isNaN(num)){      
			//alert("是数字类型!");
			if (num>sumNumber) {
				//alert("超出查询范围");
				layer.alert('超出查询范围!!',{icon:2,time:2000});
				return false;
			} else if (num<1) {
				//alert("请输入正确的页码");
				layer.alert('请输入正确的页码!',{icon:2,time:2000});
				return false;
			} else {
		 		window.location.href = "<c:url value='/findAllOrderPaging.do?u_name="+u_name+"&t_name="+t_name+"&u_phone="+u_phone+"&number="+num+"&u_nickname="+u_nickname+"&order_status="+order_status+"&start="+start+"&end="+end+"&page_num="+page_num+"'/>";
			}
		}else{      
			//alert("不是数字类型!");
			layer.alert('不是数字类型!',{icon:2,time:2000});
			return false;
		}
	}
/*
 * 验证 查询时间大小 
 */	
 function verifyDate() {
	var start = $("#start").val();
	var end = $("#end").val();
	//alert(start > end);
	if(start > end){
		//alert("开始日期不能大于结束日期!");
		layer.alert('开始日期不能大于结束日期!',{icon:2,time:3000});
		return false;		
	}
}

 /*
  * 显示隐藏状态编辑
  */	
  
  var aid;
  
  function editStatus(id,aid) {
	aid = aid;
	 $("#edit_status_show"+id).hide();
	  $("#edit_status_hidden"+id).show();
		 //$("#"+aid).parents('tr:first').css({backgroundColor:'#d1eac8'});
	// 按钮的父节点的父节点是tr。  
      /* var tr = obj.parentNode.parentNode;  
      alert(tr.rowIndex); 
      tr.setAttribute('align','center'); 
      tr.setAttribute('bgcolor','#black'); */
 }
 /**
 修改订单状态
 */
 layui.use(['form','layer'], function(){
     $ = layui.jquery;
   var form = layui.form
   ,layer = layui.layer;

   form.on('select(search_type)', function(data){
	   
	   //修改确认
	   layer.confirm('确认要修改吗？',function(index){
	   
	   
	                
	   
		console.log(data.elem); //得到select原始DOM对象
		 console.log(data.value); //得到被选中的值
		 console.log(data.othis); //得到美化后的DOM对象
		 //要更改的状态
		 var id_status = data.value;
		 //分割id 和 status
		 var flag =id_status.indexOf("_");
		var id= id_status.substring(0,flag);
		var order_status= id_status.substring(flag+1,id_status.length);
		 console.log(id +"  :  " +order_status);
		//发异步，把数据提交给php
         $.ajax({
             type: "POST",
             async : false, // 注意此处需要yi步  
             url:  "<c:url value='/updateOrderStatus.do'/>",
             data: {"id":id,"order_status":order_status,},
             success: function(data){
                 if (data == 0) {
                	 aa = 0;
                 } else  {
                	 aa = 1;
		           } 
            }
	        });   
        
         if(aa == 0){
             //layer.msg('修改失败,未知错误!',{icon: 2,time:3000});   
             layer.msg("修改失败,未知错误!", {icon: 2,time:3000},function () {
                 // 获得frame索引
                 var index = parent.layer.getFrameIndex(window.name);
                 //alert(index);
                location.reload();
             });
         }else if(aa == 1){
        	  layer.msg("修改成功", {icon: 6,time:500},function () {
                  // 获得frame索引
                  var index = parent.layer.getFrameIndex(window.name);
                  //alert(index);
                 location.reload();
        
              });
         }
       	//禁止页面自动跳转
          return false;
	   });
	});
 });
 
 layui.use('layer', function(){
     $ = layui.jquery;//jquery
   layer = layui.layer;//弹出层


     layer.ready(function(){ //为了layer.ext.js加载完毕再执行
       layer.photos({
         photos: '#x-img'
       });
     });
  
 });

</script>  
<!-- 活动操作 -->
<script type="text/javascript">
/*
启用门票
*/
  function update_promotion_status(t_id){
    layer.confirm('确认要启用吗？',function(index){
    	
        //发异步删除数据
    	$.ajax({
            type: "POST",
            async : false, // 注意此处需要yi步  
            url:  "<c:url value='/updatePromotionStatus.do'/>",
            data: {"t_id":t_id,"t_status":0},
            success: function(data){
                if (data == 0) {
                	layer.msg('启用失败,错误未知!',{icon: 2,time:3000});      
                } else  {
               	 	layer.msg("已启用", {icon: 6,time:500},function () {
                        //重新加载页面
                        location.reload();
                    });
		           } 
           }
	        }); 
    });
}
  /*
	停用门票
	*/
	  function update_promotion_status_t(t_id){
        layer.confirm('确认要停用吗？',function(index){
        	
            //发异步删除数据
        	$.ajax({
                type: "POST",
                async : false, // 注意此处需要yi步  
                url:  "<c:url value='/updatePromotionStatus.do'/>",
                data: {"t_id":t_id,"t_status":1},
                success: function(data){
                    if (data == 0) {
                    	layer.msg('停用失败,错误未知!',{icon: 2,time:3000});      
                    } else  {
                   	 	layer.msg("已停用", {icon: 6,time:500},function () {
                            //重新加载页面
                            location.reload();
                        });
 		           } 
               }
 	        }); 
        });
    }


</script>    
    <script>
	//alignmentFns.initialize();
		// 自定义类型：参数为数组，可多条数据
	//alignmentFns.createType([{"test": {"step" : 10, "min" : 10, "max" : 999, "digit" : 0}}]);
		
		// 初始化
		alignmentFns.initialize();
		
		// 销毁
		alignmentFns.destroy();
		
		// js动态改变数据
		//$("#4").attr("data-max", "12");
		// 初始化
		alignmentFns.initialize(); 
		
	</script>  
	
	<script type="text/javascript">
 	 function ck(){
		  /*   var tbodyObj = document.getElementById('dataTable');
				var i = 1 ;
		        $("table :checkbox").each(function(key,value){
			
		            if($(value).prop('checked')){
		                console.log("第"+i+"行   "+tbodyObj.rows[key].cells[1].innerHTML+ "    :  " +tbodyObj.rows[key].cells[2].innerHTML)
		            }
					i++;
		        }) */
		        
		        console.log("资料");
		        
		        $("input[type=checkbox][name=ckb_select]").click(function () {
		        	//$("input[name='ckb_select']:checkbox").click(function() {

		        	console.log("资料1");
	                var objs = $("input[type=checkbox][name=ckb_select]:checked").map(function () {
	                    var tr = $(this).closest("tr");
	                    return { "dj": $(tr).find("td:eq(1)").text(), "zhj": $(tr).find("td:eq(2)").text(), "zp": $(tr).find("td:eq(3)").text() };
	                }).get();

	                var tj = 0, zhj = 0, zp = 0;
	                $.each(objs, function (i, d) {
	                    tj = parseInt(tj) + parseInt(d.dj);
	                    zhj = parseInt(zhj) + parseInt(d.zhj);
	                    zp = parseInt(zp) + parseInt(d.zp);
	                })

					console.log(objs);
	            })
		    }
		        
		        
		        
		   function qx() {
			  // var ids = [];
			  var zongjia = 0.00;
			  var ids = [];
			  // 获取选中的id 
		       $('tbody input').each(function(index, el) {
			  	   var map = new Map();
		           if($(this).prop('checked')){
		              //ids.push($(this).val())
		              //获取数量input
		        	  var tr = $(this).closest("tr");
		              var idd = "ticket_"+$(tr).find("td:eq(1)").text();
	                  console.log($("#"+idd).val());
	                  console.log("id : "+ $(tr).find("td:eq(1)").text()+" 单价  :  "+ $(tr).find("td:eq(5)").text() + " 数量  : "+$("#"+idd).val());
	          		
	                  var id = $(tr).find("td:eq(1)").text();
	               	  var price = $(tr).find("td:eq(5)").text();
	                  var count = $("#"+idd).val();
	                  
	                  var dan_pay = price * count;
	                  console.log("id : "+id+" price: "+price+" count : "+count+" dan_pay : "+dan_pay);
	                  zongjia = zongjia + dan_pay;
	                  map["id"] = id;
	                  map["price"] = price;
	                  map["count"] = count;
	                  map["dan_pay"] = dan_pay;
	                  ids.push(map);
		           }
		       });
			   //console.log("zongjia : "+zongjia);
			   //console.log("ids.toString() : "+ids.toString());
			   var list2json=JSON.stringify(ids);
			   console.log("list2json : "+list2json);
			   
			 //发异步删除数据
	        $.ajax({
	                type: "POST",
	                async : false, // 注意此处需要yi步  
	                url:  "<c:url value='/getCodeUrl.do'/>",
	                data: {"data":list2json},
	                success: function(data){
	                    if (data == 0) {
	                    	layer.msg('结算失败,错误未知!',{icon: 2,time:3000});      
	                    } else  {
	                    	layer.msg('购票成功,等待出票!',{icon: 6,time:3000});     
	                    }
	                   	 /* 	layer.msg("结算成功", {icon: 6,time:500},function () {
	                            //重新加载页面
	                            location.reload();
	                        }); */
	 		           } 
	  
	 	        }); 
			   
			   
			   
			   
			   
			   
		}
		   
		   
		
		 
	</script>

  </body>
</html>